home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS26.ADF / ShowPt / showpoint.c < prev    next >
C/C++ Source or Header  |  1989-01-26  |  22KB  |  716 lines

  1. /************************************************************************
  2. req.c
  3.     This file contains a general-purpose <requester> that
  4. will prompt the user for a filename input.
  5.     The program actually uses a window instead of a 'Requester'
  6. for greater flexibility. It will take control of your window's
  7. IDCMP Port when called.
  8.  
  9. ***    This material is copyright (c) 1986 by C. Heath of Microsmiths, Inc.
  10. Permission is granted to use these files in any way with the following
  11. exceptions:
  12.  
  13. 1) The files shall not be posted on any telecommunications service, public
  14. or private, except for BIX until January 15, 1987.
  15.  
  16. 2) The files may only be distributed in archive format, with no modifications.
  17. If you make any improvements on the file requester and would like to
  18. generally distribute them, please contact "cheath" on BIX, or write to:
  19.     Microsmiths Inc, PO Box 561, Cambridge, MA 02140
  20.  
  21. 3) The requester may be used in any commercial product, but must be in
  22. object code format.  You are free to make modifications for use in your
  23. product.  Permission is granted to Lattice, Inc, and to Manx, Inc, to
  24. include the source files in archive format.
  25.  
  26.     Thank you, and enjoy.
  27.         ...cheath
  28.  
  29. ************************************************************************/
  30.  
  31. #include "standard.h"
  32. #include "safeclose.h"
  33. #include <stdio.h>
  34. #include <ctype.h> 
  35. #include <intuition/intuitionbase.h> 
  36. #include <exec/memory.h>
  37. #include <graphics/gfxbase.h> 
  38. #include <graphics/gfx.h> 
  39. #include <graphics/display.h> 
  40. #include <fcntl.h>
  41. #include <dos.h>
  42. #include <string.h>
  43.  
  44. #define JUNK_SIZE 28
  45. #define PHEIGHT   16
  46. #define PWIDTH    16
  47. #define PSIZE POINTERSIZE*sizeof(USHORT)
  48. #define STAN_FILE_SIZE 232
  49. #define P_FILE_SIZE     80
  50. #define NOT_FILE      0
  51. #define ORDINARY_FILE 1
  52. #define PREFS_FILE    2
  53. #define DOT_P_FILE    3
  54.  
  55. #define getred(c)   (((c) & 0x0f00) >> 8)
  56. #define getgreen(c) (((c) & 0x00f0) >> 4)
  57. #define getblue(c)  (((c) & 0x000f))
  58.  
  59. extern VOID     display(),show_old(),show_new();
  60.  
  61. #define FAST register
  62. #define NL NULL
  63.  
  64. extern char *dmore(), *dinit();
  65.  
  66. static struct FileLock      *pdir = NL;
  67. static struct FileInfoBlock *dir_info;
  68.  
  69. struct Preferences   old_prefs,my_prefs;
  70. struct IntuitionBase *IntuitionBase=NULL;
  71. struct GfxBase       *GfxBase=NULL;
  72. BYTE   Xoffset,Yoffset;          /* pointer offsets    */
  73. USHORT Color17,Color18,Color19;  /* pointer colors     */ 
  74. struct ViewPort      *my_view;
  75.  
  76. static struct TextAttr MyFont = {"topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT };
  77.  
  78. /* FGAD requires a few unique gadget-ids, origined at FGAD    */
  79. /* In the unlikely event this conflicts with any of your gadgets, */
  80. /* change this equate to allow 16 contiguous unique ID's    */
  81.  
  82. #define FGAD    0x76c0L
  83.  
  84. #define FCHARS    32L    /* Number of chars allowed in file name    */
  85.  
  86. #define DIR_SIZ    50L    /* Number of chars in a dir name...    */
  87. #define MAX_STR    DIR_SIZ+2L
  88.  
  89. #define DENTS    5L        /* Number of entries on screen   */
  90. /* It's not as simple as changing 'DENTS'...      */
  91.  
  92. #define DSIZE    FCHARS+1L    /* Size of a directory entry   */
  93.  
  94. #define    DBUFSIZ    3000L    /* Number of bytes to allocate for all ents */
  95.  
  96. #define BCOL    1L    /* Background color    */
  97. #define FCOL    2L    /* Foreground color    */
  98.  
  99. #define RHGHT    120L
  100. #define RWDTH    320L
  101.  
  102. #define ZWDTH    270L
  103.  
  104. static char    ubuf[MAX_STR];        /* Undo buffer    */
  105. static char    fbuf[MAX_STR];        /* file buffer    */
  106. static char    dbuf[MAX_STR];        /* dir  buffer    */
  107.  
  108. static struct dirent { struct dirent *next; int isfile; char dE[DSIZE+2]; };
  109. static struct dirent *FirstEntry;
  110. static struct dirent *NextEntry;
  111.  
  112. static struct dirhead { struct dirent *next; };
  113. static struct dirhead ListHead;
  114.  
  115. static long   curent,maxent;
  116. static BOOL   more;
  117.  
  118. static struct Window    *wRq = NL;        /* Requester window   */
  119. static struct RastPort    *wRp;
  120.  
  121. /* Requester "Hailing" prompt */
  122. static struct IntuiText oTxt = {2,2,JAM1,10,11,NL,(UBYTE *)"by BIT-WIZ" ,NL};
  123.  
  124. static struct IntuiText saydir = {0,1,JAM2,0,1,&MyFont,(UBYTE *)"(dir) ",NL};
  125.  
  126. static struct IntuiText rname[DENTS] = { /* File name list */
  127.    {2,1,JAM2,48,1,NL,NL, NL},
  128.    {2,1,JAM2,48,1,NL,NL, NL},
  129.    {2,1,JAM2,48,1,NL,NL, NL},
  130.    {2,1,JAM2,48,1,NL,NL, NL},
  131.    {2,1,JAM2,48,1,NL,NL, NL} };
  132.  
  133. /* Display for file name ... */
  134.  
  135. static SHORT oXY2[] = {-2,-2, RWDTH-78,-2, RWDTH-78,9, -2,9, -2,-2};
  136. static struct Border thebd = {0,0, 2,3,JAM1, 5,oXY2, NL};
  137.  
  138. static struct IntuiText otxt = {2,2,JAM1,-40,0,&MyFont,(UBYTE *)"file",NL};
  139. static struct StringInfo osx = { fbuf ,ubuf, NL,DSIZE,NL,NL,NL,NL,NL,NL,NL,NL,NL};
  140. static struct Gadget ogx = { NL, 60,RHGHT-35,RWDTH-80 ,10,     /* File name gadget */
  141.    GADGHCOMP, RELVERIFY , STRGADGET,
  142.    (APTR)&thebd,NL,&otxt,NL,(APTR)&osx, FGAD+11,NL };
  143.  
  144. static struct Gadget oga = { &ogx, 10,70, ZWDTH,10,   /* Gadgets For   */
  145.    GADGHCOMP, RELVERIFY, BOOLGADGET,     /* Directory entries   */
  146.    NL,NL, &rname[4] ,NL,NL, FGAD+10,NL };
  147. static struct Gadget og9 = {&oga, 10,60, ZWDTH,10,
  148.    GADGHCOMP, RELVERIFY, BOOLGADGET,
  149.    NL,NL, &rname[3] ,NL,NL, FGAD+9,NL };
  150. struct Gadget og8 = {&og9, 10,50, ZWDTH,10,
  151.    GADGHCOMP, RELVERIFY, BOOLGADGET,
  152.    NL,NL, &rname[2] ,NL,NL, FGAD+8,NL };
  153. static struct Gadget og7 = {&og8, 10,40, ZWDTH,10,
  154.    GADGHCOMP, RELVERIFY, BOOLGADGET,
  155.    NL,NL, &rname[1] ,NL,NL, FGAD+7,NL };
  156. static struct Gadget og6 = {&og7, 10,30, ZWDTH,10,
  157.    GADGHCOMP, RELVERIFY, BOOLGADGET,
  158.    NL,NL, &rname[0] ,NL,NL, FGAD+6,NL };
  159.  
  160.  
  161. /* Gadjets for requester  */
  162.  
  163. static SHORT oXY3[] = {0,0, 50,0, 50,9, 0,9, 0,0};
  164. static SHORT oXY4[] = {2,-2, 48,-2, 52,2, 52,7, 48,11, 2,11, -2,7, -2,2, 2,-2};
  165. static struct Border obd2 = {0,0, 2,3,JAM1, 9,oXY4, NL};
  166. static struct Border obd1 = {0,0, 3,2,JAM1, 5,oXY3, &obd2};  /* OTAY / CANCEL box */
  167.  
  168. static struct IntuiText ot1 = {0,0,JAM1,1,1,&MyFont,(UBYTE *)" Show ",NL};
  169. static struct IntuiText ot2 = {0,0,JAM1,1,1,&MyFont,(UBYTE *)" Quit ",NL};
  170.  
  171. static struct IntuiText dtxt = {2,2,JAM1,-60,0,NL,(UBYTE *)"drawer",NL};
  172. static struct StringInfo os5 = { dbuf ,ubuf, NL,DIR_SIZ,NL,NL,NL,NL,NL,NL,NL,NL,NL};
  173. static struct Gadget og5 = { &og6, RWDTH/2-80,19,190,10,     /* Directory */
  174.    GADGHCOMP, RELVERIFY, STRGADGET,
  175.    NL,NL,&dtxt,NL,(APTR)&os5, FGAD+5,NL };
  176.  
  177. static struct Image   cc_img;
  178. static struct PropInfo   cc_prop = {AUTOKNOB | FREEVERT, 0,0, 0,0x1000,0,0,0,0,0,0 };
  179. static struct Gadget og3 = { &og5,RWDTH-39,20,20,60,      /* Scroll Bar   */
  180.     GADGHCOMP,GADGIMMEDIATE | FOLLOWMOUSE, PROPGADGET,
  181.     (APTR)&cc_img,NL,NL,NL,(APTR)&cc_prop,FGAD+3,NL };
  182.  
  183. static struct Gadget og2 = { &og3, RWDTH-70,RHGHT-20, 50,10,  /* CANCEL */
  184.    GADGHCOMP,  RELVERIFY, BOOLGADGET,
  185.    (APTR)&obd1,NL, &ot2,NL,NL, FGAD+2,NL };
  186.  
  187. static struct Gadget og1 = { &og2, 20,RHGHT-20, 50,10,      /* OTAY   */
  188.    GADGHCOMP,        /* Flags    */
  189.    RELVERIFY,        /* Activation    */
  190.    BOOLGADGET,
  191.    (APTR)&obd1,NL,    /* GadgetRender, SelectRender    */
  192.    &ot1,NL,NL,        /* IntuiText, MutualExclude,SpecialInfo   */
  193.    FGAD+1,NL };        /* Gadget Id, UserData    */
  194.  
  195. /* Open a requester "Window" */
  196.  
  197. static struct NewWindow NewFiles = {
  198.    160, 30, RWDTH,RHGHT, BCOL,FCOL,CLOSEWINDOW | ACTIVEWINDOW |
  199.    INACTIVEWINDOW | MOUSEBUTTONS | GADGETDOWN | GADGETUP | MOUSEMOVE,
  200.    WINDOWCLOSE | WINDOWDEPTH | SMART_REFRESH | ACTIVATE | RMBTRAP |
  201.    WINDOWDRAG,
  202.    &og1,NL,"ShowPointers V1.0", NL,
  203.    NL, RWDTH,RHGHT,RWDTH,RHGHT, WBENCHSCREEN };
  204.  
  205.  
  206.  
  207. /***************************************************
  208. *  get_fname(window,screen,hail,ddef,ddir);
  209. *
  210. *   Displays a window/requester that
  211. * gets a file name for device,directory,default file, extension
  212. *
  213. *   Calling args:
  214. * window:   Window making the request
  215. * screen:   Screen, if NULL assummed workbench
  216. * hail:   Text prompt at top of requester
  217. * ddef:   Input default file-name. Has NO DIRECTORY OR EXTENSION.
  218. * ddir:   Directory of file, may be null
  219.  
  220. /* Set a file-requester with prompt 'hail'   */
  221.  
  222. int main()
  223. {
  224.    int status;
  225.    FAST struct IntuiMessage *imes;   /* Wait for message in HERE   */
  226.    FAST struct Gadget    *igad;   /* Get Gadjet Mumbo Jumbo   */
  227.    FAST long    i,class;
  228.    FAST TEXT    *pnam;
  229.  
  230.    FAST char    *retval;
  231.    FAST BOOL    dir_flag=0;
  232.    FAST BOOL    keepon;
  233.  
  234.    if (OpenAll()!=0) return(20);  /* error opening libraries and such */
  235.  
  236.    GetPrefs(&old_prefs,sizeof(struct Preferences));/* get the old one */
  237.    GetPrefs(&my_prefs,sizeof(struct Preferences)); /* put something here at first */
  238.  
  239.    strcpy(osx.Buffer,NULL);    /* Set default file name   */
  240.  
  241.    if (getcd(0,os5.Buffer)==0) /* get current directory   */
  242.       {
  243.        if (strchr(os5.Buffer,58)==NULL) /* add a colon if there is none */
  244.        strcat(os5.Buffer,":");
  245.       }
  246.    else 
  247.       strcpy(os5.Buffer,NULL);
  248.  
  249.    for ( i=0; i<DENTS; i++)
  250.       {
  251.       rname[i].IText = "";
  252.       rname[i].NextText = NL;
  253.       };
  254.  
  255.    if ((dir_info = (struct FileInfoBlock *)AllocMem((long)sizeof(struct FileInfoBlock),0L)) == NULL)
  256.       return(NL);
  257.  
  258.    if ( ! (FirstEntry = (struct dirent *)AllocMem((long)DBUFSIZ,0L)) ||
  259.         ! (wRq = (struct Window *)OpenWindow( &NewFiles )) )
  260.       {
  261.       if ( FirstEntry )   FreeMem(FirstEntry,(long)DBUFSIZ);
  262.       /* notify("Can't Open Requester..."); */
  263.       FreeMem(dir_info,(long)sizeof(struct FileInfoBlock));
  264.       return(NL);
  265.       }
  266.  
  267.    my_view=(struct ViewPort *) ViewPortAddress(wRq);
  268.    /* Set up directory, notify any errors...   */
  269.    if ( pnam = (char *)dinit(os5.Buffer) )   notify(pnam);
  270.  
  271.    wRp = wRq->RPort;
  272.  
  273.    SetAPen(wRp,1L);
  274.    RectFill(wRp,4L,10L,(long)(RWDTH-5),(long)(RHGHT-4));
  275.  
  276.    /* Set calling arg   */
  277.  
  278.    oTxt.LeftEdge = (RWDTH - IntuiTextLength(&oTxt)) >> 1L;
  279.  
  280.    PrintIText(wRp,&oTxt,0L,0L);
  281.  
  282.    RefreshGadgets(&og1,wRq,(long)NL);
  283.  
  284.    ActivateGadget(&ogx,wRq,0L);
  285.  
  286.    for ( retval= NL, keepon=TRUE; keepon ; )
  287.       {
  288.       while ( ! (imes=(struct IntuiMessage *)GetMsg(wRq->UserPort)) )
  289.       {
  290.          if ( dir_flag )
  291.             {
  292.             i = (maxent-DENTS) * cc_prop.VertPot / MAXBODY;
  293.             if ( i > (maxent-DENTS) )
  294.             i = maxent-DENTS;
  295.             if ( i <0 )   i = 0;
  296.             curent = i;
  297.             cxxx();
  298.             dir_flag = FALSE;
  299.             }
  300.          if ( more )
  301.             {
  302.             if (pnam = (char *)dmore())   /* Continue to read the directory */
  303.                notify(pnam);      /* Yucko error   */
  304.             if ( maxent <= DENTS ) dir_flag = TRUE;
  305.             }
  306.          else    WaitPort(wRq->UserPort);
  307.          }
  308.       igad = (struct Gadget *)imes->IAddress;
  309.       class = imes->Class;
  310.       ReplyMsg(imes);
  311.  
  312.       switch (class)
  313.          {
  314.          case ACTIVEWINDOW:
  315.               show_new();  /* put up the new sprite */
  316.               break;
  317.          case INACTIVEWINDOW:
  318.               show_old();  /* put up the old sprite */
  319.               break;
  320.          case MOUSEMOVE:
  321.               dir_flag = TRUE;
  322.               break;
  323.          case CLOSEWINDOW:
  324.               keepon = FALSE;
  325.               break;
  326.          case GADGETUP:
  327.          case GADGETDOWN:
  328.             switch ( i = igad->GadgetID)
  329.             {
  330.             case FGAD+6:
  331.             case FGAD+7:
  332.             case FGAD+8:
  333.             case FGAD+9:
  334.             case FGAD+10:       /* Replace file or directory name   */
  335.                pnam = rname[i - (FGAD+6)].IText;
  336.                if ( rname[igad->GadgetID - (FGAD+6)].NextText == NL )
  337.                   {
  338.                   RemoveGadget(wRq,&ogx);
  339.                   for (i=0; i<DSIZE; i++)      osx.Buffer[i] = *pnam++;
  340.                   AddGadget(wRq,&ogx,-1L);
  341.                   RefreshGadgets(&ogx,wRq,(long)NL);
  342.                   break;
  343.                   }
  344.                   else
  345.                   {
  346.                   RemoveGadget(wRq,&og5);
  347.                   rfnam(os5.Buffer,pnam);
  348.                   AddGadget(wRq,&og5,-1L);
  349.                   RefreshGadgets(&og5,wRq,(long)NL);
  350.                   }
  351.             case FGAD+5:
  352.                if ( pnam = (char *)dinit(os5.Buffer) )
  353.                   notify(pnam);
  354.             case FGAD+3:
  355.                dir_flag = TRUE;
  356.                break;
  357.             case FGAD+11:      /* Name gadget */
  358.                retval = osx.Buffer;
  359.                /* display file info */
  360.                if ((status=get_file())==0) show_new();
  361.                else if (status==-1) keepon = FALSE;
  362.                     else
  363.                         {
  364.                          DisplayBeep(wRq->WScreen);
  365.                          ActivateGadget(&ogx,wRq,0L);
  366.                         } 
  367.                break;
  368.             case FGAD+1:      /* SHOW gadget */
  369.                retval = osx.Buffer;
  370.                /* display file info */
  371.                if ((status=get_file())==0) show_new();
  372.                else
  373.                   {
  374.                    DisplayBeep(wRq->WScreen);
  375.                    ActivateGadget(&ogx,wRq,0L);
  376.                   } 
  377.                break;
  378.             case FGAD+2:      /* Cancel gadget   */
  379.                keepon = FALSE;
  380.                break;
  381.             }
  382.          }
  383.       }
  384.  
  385.       show_old();    /* put up the original sprite */
  386.       FreeMem(FirstEntry,(long)DBUFSIZ );
  387.       FreeMem(dir_info,(long)sizeof(struct FileInfoBlock));
  388.       free_pdir();
  389.  
  390.       CloseWindowSafely(wRq);
  391.       return(0);
  392.    }
  393.  
  394. static int free_pdir()
  395.    {
  396.    if ( pdir )
  397.       {
  398.       UnLock(pdir);
  399.       pdir = NL;
  400.       }
  401.    return(0);
  402.    }
  403.  
  404. /*****************************************************************
  405. * dinit()
  406. *   Initialize the fib for directory muck.  Null return
  407. * is good, else return is a pointer to an error string      */
  408.  
  409. static char *dinit(subdir)
  410.    char *subdir;
  411.    {
  412.    more = FALSE;
  413.    curent = maxent = 0;
  414.  
  415.    NextEntry = FirstEntry;      /* Allocate from here   */
  416.    ListHead.next = NL;          /* Clear the boogie     */
  417.  
  418.    free_pdir();   /* Unlock any old lock... */
  419.  
  420.    if (! (pdir=(struct FileLock *)Lock(subdir,(ULONG)ACCESS_READ)) )
  421.       return("Wrong Diskette?");
  422.    if ( ! Examine(pdir, dir_info) )   return("Wierd Disk Error");
  423.    if ( dir_info->fib_DirEntryType < 0L )   return("Bizzare Alert!!");
  424.  
  425.    more = TRUE;
  426.    return(dmore());
  427.    }
  428.  
  429.  
  430. static char *dmore()
  431.    {
  432.    FAST struct dirent   *p_D = NextEntry;
  433.    FAST struct dirent   *ptr = (struct dirent *)&ListHead;
  434.    FAST struct dirent   *plink;
  435.  
  436.    FAST   TEXT   *p_mung;
  437.  
  438.    FAST long    i;
  439.  
  440.    if ( ! more )   return((char *)NL);
  441.  
  442.    if ( ExNext( pdir, dir_info ) )
  443.       {
  444.  
  445.  
  446.       if ( (ULONG)p_D >=
  447.          ((ULONG)FirstEntry + (ULONG)DBUFSIZ - (ULONG)sizeof(struct dirent)) )
  448.          {
  449.          more = FALSE;
  450.          return((char *)"Directory Truncated!");
  451.          }
  452.  
  453.  
  454.       /* Here you can add a file/directory filter   */
  455.       /* filename text string is at &p_D->dE[0]   */
  456.  
  457.       if ( dir_info->fib_DirEntryType >= 0L ) p_D->isfile = NOT_FILE; /* DIR */
  458.             else
  459.                     {
  460.                      switch (dir_info->fib_Size)
  461.                             {
  462.                              case STAN_FILE_SIZE:
  463.                                                  p_D->isfile = PREFS_FILE;
  464.                                                  break;
  465.                              case P_FILE_SIZE:
  466.                                                  p_D->isfile = DOT_P_FILE;
  467.                                                  break;
  468.                    default:
  469.                                                  p_D->isfile = ORDINARY_FILE;
  470.                                                  break;
  471.                   } 
  472.                     } 
  473.  
  474.       p_mung = &p_D->dE[0];
  475.       for ( i=0; i<FCHARS; i++)
  476.          if ( ! (*p_mung++ = dir_info->fib_FileName[i]) )   break;
  477.  
  478.       i = (long)p_mung;
  479.       NextEntry = (struct dirent *)( (i+5L) & ~3L );
  480.  
  481.       for ( i=maxent++; i>=0; i--)
  482.          {
  483.          if ( ! (plink = ptr->next)  )   break;
  484.          if ( alpha_lower(p_D,plink) == 0 )   break;
  485.          ptr = plink;
  486.          }
  487.       p_D->next = plink;
  488.       ptr->next = p_D;
  489.  
  490.       return((char *)NL);
  491.       }
  492.    else return ( IoErr() == ERROR_NO_MORE_ENTRIES) ?
  493.        (char *)(more = (long)NL) : (char *)"Error Reading Directory!!!";
  494.    }
  495.  
  496.  
  497. /* dedicated alphabetizing function for dmore()   */
  498.  
  499. static alpha_lower(snew,sold)
  500.    struct dirent *snew,*sold;
  501.    {
  502.    FAST struct dirent *pnew = snew;
  503.    FAST TEXT *ps1,*ps2, c,d;
  504.  
  505.    if ( pnew->isfile == sold->isfile)
  506.       {
  507.       ps1 = &pnew->dE[0];
  508.       ps2 = &sold->dE[0];
  509.       while ( (c=*ps1++) )
  510.          {
  511.          if ( c > (d=*ps2++) )   return(FALSE);
  512.          else if ( c < d )      break;
  513.          }
  514.       return(TRUE);
  515.       }
  516.    return(pnew->isfile);
  517.    }   
  518.  
  519.  
  520.  
  521. /* Display directory stuff   */
  522.  
  523. static int cxxx()
  524.    {
  525.    FAST long   i,new;
  526.    FAST long   x,y;
  527.    FAST struct dirent *ohboy = (struct dirent *)&ListHead;
  528.  
  529.    new = curent;
  530.    for ( i=0; i<new; i++)   ohboy = ohboy->next;
  531.  
  532.    y = 20L;
  533.    for (i=0; i<DENTS; i++)
  534.       {
  535.       y += (x=10);
  536.       rname[i].NextText = NL;
  537.       rname[i].IText = "";
  538.       rname[i].LeftEdge = 0;
  539.       if ( (new+i) < maxent )
  540.          {
  541.          ohboy = ohboy->next;
  542.          rname[i].IText = &ohboy->dE[0];
  543.                  switch (ohboy->isfile)
  544.                 {
  545.                  case NOT_FILE:  /* a DIR name */
  546.                      rname[i].FrontPen=2;
  547.                      rname[i].LeftEdge = 48;
  548.                      PrintIText(wRp,&saydir,10L,y);
  549.                      PrintIText(wRp,&rname[i],10L,y);
  550.                      rname[i].NextText = &saydir;
  551.                      break;
  552.                  case PREFS_FILE:  /* pointer filename */
  553.                      rname[i].FrontPen=3;
  554.                      PrintIText(wRp,&rname[i],10L,y);
  555.                                          break;
  556.                  case DOT_P_FILE:  /* pointer filename */
  557.                      rname[i].FrontPen=3;
  558.                      PrintIText(wRp,&rname[i],10L,y);
  559.                                          break;
  560.                  default : /* normal filename */
  561.                      rname[i].FrontPen=2;
  562.                      PrintIText(wRp,&rname[i],10L,y);
  563.                                          break;
  564.                                 }
  565.          x = wRp->cp_x;
  566.          }
  567.       if ( x < ZWDTH+10 )   RectFill(wRp,x,y,(long)(ZWDTH+10),(long)(y+8L));
  568.       }
  569.     return(0);
  570.    }
  571.  
  572.  
  573. /**************************************************
  574. * rfnam()
  575. *   Combines dir, plus name into dir   */
  576.  
  577. static int rfnam(dir,fil_nam)
  578.    char *dir,*fil_nam;
  579.    {
  580.    FAST char   *pdst = dir;
  581.    FAST char   *psrc = fil_nam;
  582.    FAST char   c = ':';
  583.  
  584.    while ( *pdst )
  585.       c = *pdst++;
  586.    if ( c != ':')   *pdst++ = '/';
  587.  
  588.    while ( *pdst++ = *psrc++ )
  589.       ;
  590.     return(0);
  591.    }
  592.  
  593. static struct IntuiText b_txt = {0,1,JAM2, 5,20,NL,NL,    NL};
  594. static struct IntuiText p_txt = {0,1,JAM2, 5,3,NL,"OK", NL};
  595.  
  596. /****************************************************************/
  597. /* notify(txt)                     */
  598. /*   Prompts for Yes/No response            */
  599.  
  600. static int notify(txt)
  601.    char *txt;
  602.    {
  603.    b_txt.IText = txt;
  604.    AutoRequest(wRq,&b_txt,0L,&p_txt,0L,0L,
  605.       (long)(IntuiTextLength(&b_txt)+50L),70L);
  606.    return(0);
  607.    }
  608. /*------------------------------------------------------------------------*/
  609. VOID show_old()
  610. {
  611.    Xoffset=old_prefs.XOffset;
  612.    Yoffset=old_prefs.YOffset;
  613.    Color17=old_prefs.color17;
  614.    Color18=old_prefs.color18;
  615.    Color19=old_prefs.color19;
  616.  
  617.    display(old_prefs.PointerMatrix);
  618. }
  619. /*------------------------------------------------------------------------*/
  620. VOID show_new()
  621. {
  622.    Xoffset=my_prefs.XOffset;
  623.    Yoffset=my_prefs.YOffset;
  624.    Color17=my_prefs.color17;
  625.    Color18=my_prefs.color18;
  626.    Color19=my_prefs.color19;
  627.  
  628.    display(my_prefs.PointerMatrix);
  629. }
  630.  
  631. /*------------------------------------------------------------------------*/
  632. /*
  633.       get the sprite data file name from the user.
  634.  */
  635. int get_file()
  636. {
  637.    int      status;           /*   return code */
  638.    int      sprite_file=-1;
  639.    char     file_name[200];   /* add drawer and FileName to get this */
  640.    char     *sprite_stuff;
  641.  
  642.    if(strcmp(fbuf,NULL)==0)                /* return if no file */
  643.      return (-1);
  644.    sprite_file=-1;
  645.    strmfp(file_name,dbuf,fbuf);   /* put drawer and FileName in filename */
  646.    if((sprite_file = open(file_name,O_RDONLY,NULL)) == -1) /* can't open his file */
  647.       return (1);
  648.    sprite_stuff=(char *)&my_prefs;
  649.    status = read(sprite_file,sprite_stuff,sizeof(struct Preferences));/* try to read the data */
  650.    if(status != sizeof(struct Preferences))
  651.         {
  652.          close(sprite_file);
  653.          sprite_file = open(file_name,O_RDONLY,NULL);
  654.          sprite_stuff=(char *)&my_prefs;
  655.          sprite_stuff+=28; /* add offset for .p file */
  656.          status = read(sprite_file,sprite_stuff,sizeof(struct Preferences));/* try to read the data */
  657.          if (status != P_FILE_SIZE)
  658.             {
  659.              close(sprite_file);
  660.              return (1);
  661.             } 
  662.         }
  663.  
  664.       Xoffset=my_prefs.XOffset;
  665.       Yoffset=my_prefs.YOffset;
  666.       Color17=my_prefs.color17;
  667.       Color18=my_prefs.color18;
  668.       Color19=my_prefs.color19;
  669.  
  670.    close(sprite_file);                     /* we're done -- close it */
  671.    return (0);
  672. }
  673.  
  674. /*------------------------------------------------------------------------*/
  675. /*
  676.       display the new pointer in the window
  677.  */
  678. VOID display(spritedata)
  679. USHORT *spritedata;        /* pointer to sprite data */
  680. {
  681.    USHORT rcol,gcol,bcol;
  682.  
  683.    bcol=getblue(Color17);  /* mask in first 4 bits  */
  684.    gcol=getgreen(Color17); /* mask in middle 4 bits */
  685.    rcol=getred(Color17);
  686.    SetRGB4(my_view,17,rcol,gcol,bcol);
  687.  
  688.    bcol=getblue(Color18);  /* mask in first 4 bits  */
  689.    gcol=getgreen(Color18); /* mask in middle 4 bits */
  690.    rcol=getred(Color18);
  691.    SetRGB4(my_view,18,rcol,gcol,bcol);
  692.  
  693.    bcol=getblue(Color19);  /* mask in first 4 bits  */
  694.    gcol=getgreen(Color19); /* mask in middle 4 bits */
  695.    rcol=getred(Color19);
  696.    SetRGB4(my_view,19,rcol,gcol,bcol);
  697.  
  698.    SetPointer(wRq,spritedata,PHEIGHT,PWIDTH,Xoffset,Yoffset);
  699.  
  700. }
  701. /*------------------------------------------------------------------------*/
  702. /* open intution */
  703. OpenAll()
  704. {
  705.    IntuitionBase=(struct IntuitionBase *) 
  706.           OpenLibrary("intuition.library",32);
  707.    if(IntuitionBase==NULL) return(1);
  708. /* open Gfx */
  709.    GfxBase=(struct GfxBase *) 
  710.           OpenLibrary("graphics.library",32);
  711.    if(GfxBase==NULL) return(1);
  712.    return(0);
  713.  
  714. }
  715.  
  716.